package net.yihang.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import javax.sql.DataSource;

@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:spring.xml")
@WebAppConfiguration
public class InitDatabase {

    @Autowired
    private DataSource dataSource;

    @Value("classpath:init.sql")
    private Resource resource;

    @Test
    public void test() {
        ResourceDatabasePopulator dp = new ResourceDatabasePopulator(resource);
        dp.execute(dataSource);
    }
}
